<template>
	<view style="width: 100%;    margin: 5px;">
		<view v-if="!!proList.length">
			<view class="pro_item" v-for="(item, index) in proList" v-if="item.noticeDisplay == '是'" :key="index" @tap="goProDetails(item.noticeId)">{{ (index + 1) + '、' + item.noticeTitle }}</view>
		</view>
		<view v-else class="nothing">
			<image src="../../static/img/nothing.png"></image>
		</view>
	</view>
</template>

<script>
import api from '../../api/homeApi.js';
import otherApi from '../../api/otherApi.js';
import utils from '../../api/utils.js';

export default {
	data() {
		return {
			pages: {
				pageSize: 15,
				pageNum: 1,
				total: 0
			},
			proList: []
		};
	},
	methods: {
		// 进入公告详情
		goProDetails(id) {
			uni.navigateTo({
				url: `../proclamation/proContent?id=${id}`
			});
		}
	},
	async onShow() {
		let _this = this;
		let token = "";
		uni.showLoading({
			title: 'Please wait...',
			mask: true
		});
		uni.getStorage({
			key: 'token',
			success(res) {
				token = res.data
			}
		})
		if (utils.userType == '学生' && utils.platform == 'android') {
			uni.getLocation({
				type: 'wgs84',
				geocode: true,
				async success(res) {
					let Position = {};
					Position = {
						address: (res.address.country + res.address.province + res.address.city + res.address.district + res.address.street + res.address.streetNum).replace(
							/undefined/g,
							''
						),
						latitude: res.latitude,
						longitude: res.longitude
					};
					let savePosition = await otherApi.savePosition('position/savePosition', Position, token);
				}
			});
			setInterval(async () => {
				let Position = {};
				uni.getLocation({
					type: 'wgs84',
					geocode: true,
					async success(res) {
						let Position = {};
						Position = {
							address: (res.address.country + res.address.province + res.address.city + res.address.district + res.address.street + res.address.streetNum).replace(
								/undefined/g,
								''
							),
							latitude: res.latitude,
							longitude: res.longitude
						};
						await otherApi.savePosition('position/savePosition', Position, token);
					}
				}); 
			}, 900000);
		}
		let data = await api.getProclamation(token);
		if (data.head.status) {
			_this.proList = data.body;
		} else {
			uni.showToast({
				title: data.head.msg,
				icon: 'none',
				duration: 2000
			});
		}
		uni.hideLoading();
	}
};
</script>

<style scoped>
.pro_list {
	width: 100%;
	height: 100vh;
	box-sizing: border-box;
}

.pro_item {
	width: 90%;
	padding: 10px 15px;
	margin-bottom: 10px;
	border-bottom: solid 1px #eee;
	color: #666;
	font-size: 13px;
}

.nothing {
	width: 100%;
	text-align: center;
}

.nothing image {
	width: 150px;
	height: 150px;
	margin-top: 50%;
}
</style>
